package com.lzt.admin.common.result;

import com.lzt.admin.api.result.ResultAPI;

import java.util.HashMap;

public class ResultJson extends HashMap<String,Object> implements ResultAPI {
    public ResultJson add(String key, Object value) {
        this.put(key, value);
        return this;
    }

    private static ResultJson getJson(Integer code, String msg) {
        ResultJson json = new ResultJson();
        json.put(CODE_TAG,code);
        json.put(MSG_TAG,msg);
        return json;
    }

    public static ResultJson success() {
        return getJson(DEFAULT_HTTP_SUCCESS_CODE, DEFAULT_HTTP_SUCCESS_MSG);
    }

    public static ResultJson success(Integer code) {
        return getJson(code,DEFAULT_HTTP_SUCCESS_MSG);
    }

    public static ResultJson success(String msg) {
        return getJson(DEFAULT_HTTP_SUCCESS_CODE, msg);
    }

    public static ResultJson success(Integer code, String msg) {
        return getJson(code, msg);
    }

    public static ResultJson fail() {
        return getJson(DEFAULT_HTTP_ERROR_CODE, DEFAULT_HTTP_ERROR_MSG);
    }

    public static ResultJson fail(Integer code) {
        return getJson(code,DEFAULT_HTTP_ERROR_MSG);
    }

    public static ResultJson fail(String msg) {
        return getJson(DEFAULT_HTTP_ERROR_CODE, msg);
    }

    public static ResultJson fail(Integer code, String msg) {
        return getJson(code, msg);
    }
}
